import {IStoreGoodsPageRow, IStoreProductRow} from "@/api/modules/pointsMall";
import {IGiftPackGoodProduct, IGiftPackGoodsEntity} from "@/api/modules/vipCenter";

export function useAddGiftPackPrize() {
  const makeGoodsEntity: (rowData: IStoreGoodsPageRow) => IGiftPackGoodsEntity = (rowData) => {
    const _goodsEntity = {} as any
    _goodsEntity.storeGoodsId = rowData.id
    _goodsEntity.name = rowData.name
    _goodsEntity.thumbnailUrl = rowData.thumbnailUrl
    _goodsEntity.detailText = rowData.detailText
    _goodsEntity.description = rowData.description
    _goodsEntity.addOrDeductionStockCount = 1
    _goodsEntity.products = []
    _goodsEntity.type = rowData.type
    _goodsEntity.storeId = rowData.storeId
    _goodsEntity.storeName = rowData.storeName

    return _goodsEntity
  }

  // 为form goodsEntity创建一个product
  const makeGoodsProduct: (productRow: IStoreProductRow, goodsRow: IStoreGoodsPageRow) => IGiftPackGoodProduct = (productRow, goodsRow) => {
    const _product = {} as any
    _product.storeProductId = productRow.id
    _product.storeGoodsId = goodsRow.id
    _product.name = productRow.name
    _product.thumbnailUrl = productRow.thumbnailUrl
    _product.addOrDeductionStockCount = 1
    _product.beforeStock = productRow.beforeStock

    return _product
  }

  return {
    makeGoodsEntity,
    makeGoodsProduct
  }
}
